from .import constants
from django.http import HttpResponse
from django.shortcuts import render
import logging
# Create your views here.

# 日志器
from utils.captcha.captcha import captcha
logger = logging.getLogger('django')


def image_code_view(request):
    """
    生成图片验证码
    :param request:
    url  :image_code/
    :return:
    """
    #获取验证码 图片
    text, image = captcha.generate_captcha()
    request.session['image_code'] = text
    # 将验证码存入session中
    request.session.set_expiry(constants.IMAGE_CODE_EXPIRES)
    logger.info('Image code:{}'.format(text))

    return HttpResponse(content=image, content_type='image/jpg')